package cz.zcu.fav.rat.security.beans;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;

import cz.zcu.fav.rat.dataaccess.service.UserService;
import cz.zcu.fav.rat.rest.errorhandling.UnauthorizedAccessRestException;

public class UserSessionController
{

	@Autowired
	private static UserService userService;
	
	public static UserDetailsBean getLoggedUserBean()
			throws UnauthorizedAccessRestException
	{
		java.lang.Object principal = SecurityContextHolder.getContext()
				.getAuthentication().getPrincipal();

		if (principal instanceof UserDetailsBean)
		{
			return (UserDetailsBean) principal;
		}
		throw new UnauthorizedAccessRestException(
				"It looks you are not authorized. Please provide corresponding credentials.");
	}

}
